<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button id="btn1">按钮1</button>
    <button id="btn2">按钮2</button>
    <button id="btn3">按钮3</button>
    <button id="btn4">按钮4</button>




    <script>
        // 位置对象  提供窗口加载的文档的相关信息
        // location 比较提别,document和window当中的location是同一个对象
        console.log(window.location);
        console.log(document.location);
        console.log(window.location == document.location);

        //----- 常见属性
        //hash：如果url中包含#，则能够返回#后面的内容
        // url:https://www.baidu.com/index.html#welcome
        // console.log(location.hash);//#welcome
        // host:服务器的名字
        // console.log(location.host);//www.baidu.com
        //当前页面的完整路径
        console.log(location.href);

        //获取btn1
        let btn1 = document.getElementById('btn1');
        btn1.onclick = function () {
            // 跳转到百度
            location.href = 'https://www.baidu.com/'
        }

        //常见方法
        //重新加载文档
        let btn2 = document.getElementById('btn2');
        btn2.onclick = function () {
            location.reload()
        }

        //加载一个新的文档
        let btn3 = document.getElementById('btn3');
        btn3.onclick = function () {
            location.assign('index.html')
        }

        //替换当前文档
        let btn4 = document.getElementById('btn4');
        btn4.onclick = function () {
            // location.replace('index.html');
            // location = 'https://www.baidu.com/'
            // window.location='https://www.baidu.com/'
        }

        //跳转
        // location.href='XXXX'
        // location.assign('XXX')
        // location.replace('XXX')
        // location='https://www.baidu.com/'
        // window.location='https://www.baidu.com/'


        





    </script>

</body>

</html>